package com.cui.myadapterdemo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.Toast;

import org.kymjs.kjframe.ui.BindView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends Activity {
    private ListView mListView;
    private List<String> mDatas = new ArrayList<String>(Arrays.asList("Hello",
            "World", "Welcome"));
    private List<Model> modelList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mListView = (ListView) findViewById(R.id.id_lv_main);
        initData();
        mListView.setAdapter(myAdapter());
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(MainActivity.this, modelList.get(i).getTitle(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    private BaseAdapter myAdapter() {
        BaseAdapter mAdapter = new CommonAdapter<Model>(
                getApplicationContext(), modelList, R.layout.item
        ) {
            @Override
            public void convert(ViewHolder holder, Model model) {
                holder.setText(R.id.id_tv_title, model.getName());
                holder.setImgByUrl(R.id.roundImageview, model.getImageUrl());
                holder.setText(R.id.id_tv_title1, model.getName());

            }
        };
        return mAdapter;
    }

    private void getMy() {
        BaseAdapter baseAdapter = new CommonAdapter<Model>(getApplicationContext(), modelList, R.layout.item) {
            @Override
            public void convert(ViewHolder holder, Model item) {

            }
        };
    }

    private void initData() {
        modelList.clear();
        for (int i = 0; i < 10; i++) {
            Model model = new Model();
            model.setName("hello" + (i + 1));
            model.setTitle("这里是：" + model.getName());
            model.setImageUrl("http://img3.redocn.com/tupian/20150806/weimeisheyingtupian_4779232.jpg");
            modelList.add(model);
        }
    }
}
